﻿using System.IO;
using System.Text;
using System.Web.Mvc;
using HtmlAgilityPack;
using Mvc.RazorTools;
using Mvc.RazorTools.Glyphicons;

namespace Mvc.RazorTools.Glyphicons.Tests
{
	public static class TestExtensions
	{
		public static HtmlNode HtmlNode(this Glyphicon item)
		{
			return TestExtensions.GetNode(item.Html.ToString());
		}

		public static HtmlNode HtmlNode(this MvcHtmlString item)
		{
			return TestExtensions.GetNode(item.ToString());
		}

		internal static HtmlNode GetNode(string html)
		{
			HtmlDocument returnValue = new HtmlDocument();

			byte[] data = ASCIIEncoding.ASCII.GetBytes(html);
			using (MemoryStream io = new MemoryStream(data))
			{
				returnValue.Load(io);
				io.Close();
			}

			return returnValue.DocumentNode.ChildNodes[0];
		}
	}
}
